<template>
  <div class="bpm-button">
    <!--按钮toolbar-->
    <a-spin :spinning="spinning != 0" style="margin-bottom: 16px;">
      <a-affix :target="getAffixTarget">
        <div class="bpm-title-toolbar">
          <span style="max-width: 350px" class="bpm-title-group" :title="father.processInstanceName">{{father.processInstanceName}}</span>
          <span class="bpm-title-group" v-if="processInstanceStatus"><em>{{processInstanceStatus}}</em></span>
          <div class="bpm-button-group">
            <a-button :icon="button.icon" v-for="(button, index) in buttonVoList" :key="button.id"
                      @click="callFn(button)"
                      :type="button.buttonStyle || 'default'" v-if="index < size && !hiddenButton[button.type]">
              {{button.label}}
            </a-button>
            <a-dropdown v-if="buttonVoList.length > size">
              <a-menu slot="overlay">
                <a-menu-item v-for="(button, index) in buttonVoList" :key="button.id" v-if="index >= size && !hiddenButton[button.type]">
                  <a @click="callFn(button)">{{button.label}}</a>
                </a-menu-item>
              </a-menu>
              <a-button icon="more"> {{$t('m.common.button.more')}}
                <ych-icon type="down"/>
              </a-button>
            </a-dropdown>
            <!--<a-button icon="fork" v-if="currentTaskInstanceVo != null && taskInstanceVoList.length > 1"
                      @click="changeCurrentTask()">
              切换任务
            </a-button>-->

            <!--<a-tooltip>
              <template slot="title">
                <div v-if="currentTaskInstanceVo != null">
                  当前身份：{{identity}}
                </div>
                <div v-if="currentUsers != null">
                  当前办理人：{{currentUsers}}
                </div>
                <div v-if="currentPassRoundUsers != null">
                  当前传阅人：{{currentPassRoundUsers}}
                </div>
              </template>
              <a-button icon="info-circle">状态</a-button>
            </a-tooltip>-->
            <a-button v-show="father.showCloseBut" type="link" icon="close" @click="father.close()">
            </a-button>
          </div>
        </div>
      </a-affix>
    </a-spin>


    <!--切换任务选择对话框-->
    <bpm-button-common-dialog ref="changeTaskDialog" :title="$t('m.bpm.verify.tip_switch_tasks')" :dataVoList="taskInstanceVoList"
                              @selectOk="changeTask"></bpm-button-common-dialog>

    <!--办理分支选择对话框-->
    <bpm-button-common-dialog ref="transitionDialog" :title="$t('m.bpm.verify.tip_select_transition')" :dataVoList="transitionList"
                              @selectOk="doSubmit"></bpm-button-common-dialog>

    <!--启动流程模板选择对话框-->
    <bpm-button-common-dialog ref="processDefDialog" :title="$t('m.bpm.verify.tip_select_process_template')" :dataVoList="processDefList"
                              @selectOk="doStartModalBack"></bpm-button-common-dialog>

    <!--跳转、退回指定节点等流程节点选择对话框-->
    <bpm-button-common-dialog ref="activityDialog" :title="$t('m.bpm.verify.tip_select_target_node')" :dataVoList="activityList"
                              @selectOk="doActivityBack"></bpm-button-common-dialog>

    <!--流程选人对话框-->
    <bpm-select-user-dialog ref="bpmSelectUserDialog" @selectUserBack="selectUserBack"></bpm-select-user-dialog>

    <!--流程跟踪对话框-->
    <bpm-track-dialog ref="bpmTrackDialog"></bpm-track-dialog>

    <!--指派后续节点处理人对话框-->
    <set-instance-users-dialog ref="setInstanceUsersDialog" :title="$t('m.bpm.verify.tip_assign_user')" :activity-list="activityList"
                               :button="button"></set-instance-users-dialog>
    <bpm-collection-dialog ref="bpmCollectionDialog"></bpm-collection-dialog>
  </div>
</template>

<script>

  import { postAction, putAction, getAction } from '@/api/manage'
  import BpmSelectUserDialog from './bpmButton/BpmSelectUserDialog'
  import BpmTrackDialog from './BpmTrackDialog'
  import SetInstanceUsersDialog from './bpmButton/SetInstanceUsersDialog'
  import BpmButtonCommonDialog from './bpmButton/BpmButtonCommonDialog'
  import YchConstant from '@/api/YchConstant'
  import BpmCollectionDialog from './BpmCollectionDialog'

  export default {
    name: 'BpmButton',
    props: {
      /*formId: {
        type: String,
        default: null
      },*/
      /*variables: {
        type: Object,
        default: {}
      },*/
      father: {
        type: Object,
        default: {}
      }
    },
    components: {
      BpmSelectUserDialog,
      BpmTrackDialog,
      SetInstanceUsersDialog,
      BpmButtonCommonDialog,
      BpmCollectionDialog
    },
    data() {
      return {
        url: {
          getBpmOperateVo: YchConstant.PREFIX_BPM + '/bpm-front/displayRest/getBpmOperateVo/v1',
          getDealData: YchConstant.PREFIX_BPM + '/bpm-front/displayRest/getDealData/v1',
          start: YchConstant.PREFIX_BPM + '/bpm-front/operateRest/startByProcessDefId/v1',
          reStart: YchConstant.PREFIX_BPM + '/bpm-front/operateRest/reStart/v1',
          submit: YchConstant.PREFIX_BPM + '/bpm-front/operateRest/submit/v1',
          addUser: YchConstant.PREFIX_BPM + '/bpm-front/operateRest/addUser/v1',
          addUserAndSubmit: YchConstant.PREFIX_BPM + '/bpm-front/operateRest/addUserAndSubmit/v1',
          removeUser: YchConstant.PREFIX_BPM + '/bpm-front/operateRest/removeUser/v1',
          addPassRound: YchConstant.PREFIX_BPM + '/bpm-front/operateRest/addPassRound/v1',
          addPassRoundAndSubmit: YchConstant.PREFIX_BPM + '/bpm-front/operateRest/addPassRoundAndSubmit/v1',
          removePassRound: YchConstant.PREFIX_BPM + '/bpm-front/operateRest/removePassRound/v1',
          addReader: YchConstant.PREFIX_BPM + '/bpm-front/operateRest/addReader/v1',
          removeReader: YchConstant.PREFIX_BPM + '/bpm-front/operateRest/removeReader/v1',
          delegateTask: YchConstant.PREFIX_BPM + '/bpm-front/operateRest/delegateTask/v1',
          jump: YchConstant.PREFIX_BPM + '/bpm-front/operateRest/jump/v1',
          rejectPreTask: YchConstant.PREFIX_BPM + '/bpm-front/operateRest/rejectPreTask/v1',
          rejectFirstTask: YchConstant.PREFIX_BPM + '/bpm-front/operateRest/rejectFirstTask/v1',
          rejectWantTask: YchConstant.PREFIX_BPM + '/bpm-front/operateRest/rejectWantTask/v1',
          finishPassRound: YchConstant.PREFIX_BPM + '/bpm-front/operateRest/finishPassRound/v1',
          reBack: YchConstant.PREFIX_BPM + '/bpm-front/operateRest/reBack/v1',
          reBackFirst: YchConstant.PREFIX_BPM + '/bpm-front/operateRest/reBackFirst/v1',
          reDelegateTask: YchConstant.PREFIX_BPM + '/bpm-front/operateRest/reDelegateTask/v1',
          transferTask: YchConstant.PREFIX_BPM + '/bpm-front/operateRest/transferTask/v1',
          pressTodo: YchConstant.PREFIX_BPM + '/bpm-front/operateRest/pressTodo/v1',
          suspend: YchConstant.PREFIX_BPM + '/bpm-front/operateRest/suspend/v1',
          activate: YchConstant.PREFIX_BPM + '/bpm-front/operateRest/activate/v1',
          getProcessDefListByFormCode: YchConstant.PREFIX_BPM + '/bpm-front/displayRest/getProcessDefListByFormCode/v1'
        },
        getBpmOperateVoUrl: null,
        bpmId: null,//当前数据ID
        bpmIdType: null,//当前数据ID的类型，可以是 formCode formId processInstanceId taskId processDefId，类型为formCode时，bpmId为随机数
        buttonVoList: [],//所有的操作按钮
        currentUsers: null,//当前办理人
        currentPassRoundUsers: null,//当前传阅人
        currentTaskInstanceVo: null,//当前任务的vo对象
        spinning: 0,//组件遮罩，成对控制
        activityList: [],//跳转、退回指定节点等流转节点选择；指派处理人节点数据
        activityType: null,//记录当前选择流程节点的动作的类型，选择流程节点后的回调使用
        processDefList: [],//启动流程模板选择
        transitionList: [],//办理分支选择
        taskInstanceVoList: [],//切换任务选择
        isStart: false,//标识当前的刷新事件是否因为启动流程导致，用于启动流程后的自动打开办理页面的判断
        currentUrl: null,//记录当前动作需要调用的url，回调使用
        button: null,//记录当前动作对应的button，回调使用
        hideIdeaDialog: false,// 办理时隐藏意见框
        targetOffset: undefined,
        fullWidth: document.documentElement.clientWidth,
        hiddenButton: {} // 控制按钮显隐
      }
    },
    methods: {
      setHiddenButton(hiddenButton) {
        this.hiddenButton = hiddenButton || {}
      },
      /*流程操作按钮动态调用*/
      callFn(button) {
        this[button.type].apply(this, [button])
      },
      /*保存、保存草稿*/
      save(button) {
        this.button = button
        //是否保存草稿
        let isDraft = button.attribute.processInstanceId?false:true
        this.$emit('save',undefined,undefined,isDraft)
      },
      /*启动*/
      start(button) {
        this.button = button
        const that = this
        /*当没有流程模板ID时，说明是从业务模块中启动的，此时需要先计算流程模板ID*/
        if (!this.button.attribute.processDefId) {
          that.spinning++
          getAction(this.url.getProcessDefListByFormCode, { formCode: this.father.layoutCode || this.father.formCode }).then((res) => {
            if (res.success) {
              if (res.result.length == 0) {
                that.messageUtil.warning(that.$t('m.bpm.verify.tip_process_template_not_found_for_formcode',[this.father.layoutCode || this.father.formCode]))
              } else if (res.result.length == 1) {
                /*只有一个流程模板时，默认使用*/
                that.button.attribute.processDefId = res.result[0].id
                that.doStart()
              } else {
                that.processDefList = res.result
                that.processDefList.forEach(vo => {
                  vo.text = vo.name + '-V' + vo.version
                })
                this.$refs.processDefDialog.visible = true
              }
            } else {
              that.messageUtil.warning(res.message)
            }
          }).finally(() => {
            that.spinning--
          })
        } else {
          this.doStart()
        }
      },
      /*选择启动流程模板后的回调*/
      doStartModalBack(processDef) {
        this.button.attribute.processDefId = processDef.id
        this.doStart()
      },
      /*实际启动，可能和保存业务数据同时启动，也可能单独调用启动流程接口*/
      doStart() {
        /*若没有formId，则调用业务数据保存接口，业务数据保存接口中启动流程；
        若有formId，则直接调用启动流程接口，需要在页面上获取到业务数据的流程变量*/
        /*if (!this.formId) {
          this.$emit("save", this.startBack, this.button.attribute.processDefId);
        } else {
          const that = this;
          that.spinning++;
          postAction(this.url.start + "?id=" + this.button.attribute.processDefId + "&formId=" + this.formId, this.variables).then((res) => {
            if (res.success) {
              that.messageUtil.success(res.message);
              that.bpmId = res.result;
              that.bpmIdType = "processInstanceId";
              that.isStart = true;
              that.refresh();
              that.refreshParent();
            } else {
              that.messageUtil.warning(res.message);
            }
          }).finally(() => {
            that.spinning--;
          });
        }*/
        this.$emit('save', this.startBack, this.button.attribute.processDefId)
      },
      /*调用业务数据保存并启动流程后的回调*/
      startBack(formId) {
        this.messageUtil.success(this.$t('m.bpm.verify.tip_start_sucess'))
        this.bpmId = formId
        this.bpmIdType = 'formId'
        this.isStart = true
        this.refresh()
        // this.refreshParent();
      },
      /*办理*/
      submit(button) {

        // TODO 移动端办理和保存的关系的处理

        // 如果有保存权限，则先保存，再回调办理；如果没有保存权限，则直接办理
        const saveButton = this.buttonVoList.find(vo => vo.type === "save");
        if (saveButton) {
          this.button = button
          this.$emit('save', this.submitBack)
        } else {
          this.button = button
          this.submitBack();
        }
      },
      submitBack() {
        const that = this
        that.spinning++
        getAction(this.url.getDealData, {taskId: this.button.attribute.taskId}).then((res) => {
          if (res.success) {
            that.hideIdeaDialog = res.result.hideIdeaDialog;
            if (res.result.last) {
              if (res.result.transitionList.length == 0) {
                that.messageUtil.warning(this.$t('m.bpm.verify.tip_no_transition'))
              } else if (res.result.transitionList.length == 1) {
                /*只有一个流转方向时，默认使用*/
                that.doSubmit(res.result.transitionList[0])
              } else {
                that.transitionList = res.result.transitionList
                that.transitionList.forEach(vo => {
                  vo.text = vo.name
                })
                that.$refs.transitionDialog.visible = true
              }
            } else {
              /*不是当前节点的最后一个任务，则只需要填写意见*/
              that.doSubmit()
            }
          } else {
            that.messageUtil.warning(res.message)
          }
        }).finally(() => {
          that.spinning--
        })
      },
      /*实际办理或选择流转目标后的回调*/
      doSubmit(transition) {
        this.currentUrl = this.url.submit + '?taskId=' + this.button.attribute.taskId
        if (transition) {
          this.$refs.bpmSelectUserDialog.openForSubmit(this.button, transition, this.hideIdeaDialog)
        } else {
          this.$refs.bpmSelectUserDialog.openNoUser(this.button, this.hideIdeaDialog)
        }
      },
      /*重新启动流程*/
      reStart(button) {
        const that = this
        this.currentUrl = this.url.reStart + '?id=' + button.attribute.processInstanceId
        this.$confirm({
          content: that.$t('m.bpm.verify.confirm_reStart'),
          onOk() {
            that.spinning++
            postAction(that.currentUrl, {}).then((res) => {
              if (res.success) {
                that.messageUtil.success(res.message)
                that.refresh()
                that.refreshParent()
              } else {
                that.messageUtil.warning(res.message)
              }
            }).finally(() => {
              that.spinning--
            })
          },
          onCancel() {
          }
        })
      },
      /*加签*/
      addUser(button) {
        this.currentUrl = this.url.addUser + '?taskId=' + button.attribute.taskId
        this.$refs.bpmSelectUserDialog.open(button)
      },
      /*加签并完成*/
      addUserAndSubmit(button) {
        this.currentUrl = this.url.addUserAndSubmit + '?taskId=' + button.attribute.taskId
        this.$refs.bpmSelectUserDialog.open(button)
      },
      /*减签*/
      removeUser(button) {
        this.currentUrl = this.url.removeUser + '?taskId=' + button.attribute.taskId
        this.$refs.bpmSelectUserDialog.open(button)
      },
      /*增加传阅人*/
      addPassRound(button) {
        this.currentUrl = this.url.addPassRound + '?taskId=' + button.attribute.taskId
        this.$refs.bpmSelectUserDialog.open(button)
      },
      /*增加传阅人并完成*/
      addPassRoundAndSubmit(button) {
        this.currentUrl = this.url.addPassRoundAndSubmit + '?taskId=' + button.attribute.taskId
        this.$refs.bpmSelectUserDialog.open(button)
      },
      /*减少传阅人*/
      removePassRound(button) {
        this.currentUrl = this.url.removePassRound + '?taskId=' + button.attribute.taskId
        this.$refs.bpmSelectUserDialog.open(button)
      },
      /*增加读者*/
      addReader(button) {
        this.currentUrl = this.url.addReader + '?taskId=' + button.attribute.taskId
        this.$refs.bpmSelectUserDialog.open(button)
      },
      /*减少读者*/
      removeReader(button) {
        this.currentUrl = this.url.removeReader + '?taskId=' + button.attribute.taskId
        this.$refs.bpmSelectUserDialog.open(button)
      },
      /*委托*/
      delegateTask(button) {
        this.currentUrl = this.url.delegateTask + '?taskId=' + button.attribute.taskId
        this.$refs.bpmSelectUserDialog.open(button)
      },
      /*取消委托*/
      reDelegateTask(button) {
        this.currentUrl = this.url.reDelegateTask + '?taskId=' + button.attribute.taskId
        this.$refs.bpmSelectUserDialog.openNoUser(button)
      },
      /*转办*/
      transferTask(button) {
        this.currentUrl = this.url.transferTask + '?taskId=' + button.attribute.taskId
        this.$refs.bpmSelectUserDialog.open(button)
      },
      /*催办*/
      pressTodo(button) {
        this.currentUrl = this.url.pressTodo + '?taskId=' + button.attribute.taskId
        this.$refs.bpmSelectUserDialog.open(button)
        this.$refs.bpmSelectUserDialog.title = button.label + '：' + button.attribute.taskPressTodoType
      },
      /*跳转*/
      jump(button) {
        this.activityList = JSON.parse(button.attribute.activityVoList)
        this.activityList.forEach(vo => {
          vo.text = vo.name
        })
        this.$refs.activityDialog.visible = true
        this.activityType = 'jump'
        this.button = button
      },
      /*指派后续节点处理人*/
      setInstanceUsers(button) {
        this.button = button
        this.activityList = JSON.parse(button.attribute.activityVoList)
        this.$refs.setInstanceUsersDialog.visible = true
      },
      /*退回上一步*/
      rejectPreTask(button) {
        this.currentUrl = this.url.rejectPreTask + '?taskId=' + button.attribute.taskId
        this.$refs.bpmSelectUserDialog.openNoUser(button)
      },
      /*退回申请人*/
      rejectFirstTask(button) {
        this.currentUrl = this.url.rejectFirstTask + '?taskId=' + button.attribute.taskId
        this.$refs.bpmSelectUserDialog.openNoUser(button)
      },
      /*退回指定节点*/
      rejectWantTask(button) {
        this.activityList = JSON.parse(button.attribute.activityVoList)
        this.activityList.forEach(vo => {
          vo.text = vo.name
        })
        this.activityType = 'rejectWantTask'
        this.button = button
        if (this.activityList.length === 1) {
          this.doActivityBack(this.activityList[0]);
        } else {
          this.$refs.activityDialog.visible = true
        }
      },
      /*填写传阅意见*/
      finishPassRound(button) {
        this.currentUrl = this.url.finishPassRound + '?taskId=' + button.attribute.taskId
        this.$refs.bpmSelectUserDialog.openNoUser(button)
      },
      /*收回*/
      reBack(button) {
        this.currentUrl = this.url.reBack + '?taskId=' + button.attribute.taskId
        this.$refs.bpmSelectUserDialog.openNoUser(button)
      },
      /*撤销*/
      reBackFirst(button) {
        this.currentUrl = this.url.reBackFirst + '?taskId=' + button.attribute.taskId
        this.$refs.bpmSelectUserDialog.openNoUser(button)
      },
      /*挂起*/
      suspend(button) {
        const that = this
        this.currentUrl = this.url.suspend + '?processInstanceId=' + button.attribute.processInstanceId
        this.$confirm({
          content: that.$t('m.bpm.verify.confirm_suspend'),
          onOk() {
            that.selectUserBack()
          },
          onCancel() {
          }
        })
      },
      /*恢复*/
      activate(button) {
        const that = this
        this.currentUrl = this.url.activate + '?processInstanceId=' + button.attribute.processInstanceId
        this.$confirm({
          content: that.$t('m.bpm.verify.confirm_activate'),
          onOk() {
            that.selectUserBack()
          },
          onCancel() {
          }
        })
      },
      /*打开流程跟踪*/
      bpmTrack(button) {
        this.button = button
        this.$refs.bpmTrackDialog.open(button.attribute.processInstanceId,button.attribute.processDefId)
      },
      //收藏
      bpmCollection(button){
        this.button = button
        this.$refs.bpmCollectionDialog.open(button.attribute.processInstanceId,this.father.processInstanceName)
      },
      /*刷新按钮权限等，即组件加载*/
      refresh: function() {
        this.buttonVoList = []
        this.taskInstanceVoList = []
        this.currentTaskInstanceVo = null
        this.currentUsers = null
        this.currentPassRoundUsers = null
        if (!this.bpmId) {
          return
        }
        const that = this
        if (this.getBpmOperateVoUrl) {
          this.url.getBpmOperateVo = this.getBpmOperateVoUrl
        }
        that.spinning++
        getAction(this.url.getBpmOperateVo, {
          id: this.bpmId,
          idType: this.bpmIdType,
          formCode: this.father.layoutCode || this.father.formCode
        }).then((res) => {
          if (res.success) {
            that.setButtonDatas(res.result)
            that.$emit("afterBpmRefresh", res.result)
          } else {
            that.messageUtil.warning(res.message)
          }
        }).finally(() => {
          that.spinning--
        })
      },
      setButtonDatas(buttonDatas) {
        const that = this
        that.buttonVoList = buttonDatas.buttonVoList
        that.taskInstanceVoList = buttonDatas.taskInstanceVoList
        that.currentTaskInstanceVo = buttonDatas.currentTaskInstanceVo
        that.currentUsers = buttonDatas.currentUsers
        that.currentPassRoundUsers = buttonDatas.currentPassRoundUsers
        that.bpmId = buttonDatas.bpmId
        that.bpmIdType = buttonDatas.bpmIdType

        this.father.setEditableList(buttonDatas.editableList || [], this.bpmIdType == 'formCode' || this.bpmIdType == 'processDefId' || this.bpmIdType == 'formId', buttonDatas.requiredList || [], buttonDatas.hiddenList || [])
        this.father.setCurProcessData(buttonDatas)

        if (that.bpmIdType == 'taskId' && that.currentTaskInstanceVo == null) {
          that.messageUtil.warning(that.$t('m.bpm.verify.tip_no_permission'))
          this.father.close()
        } else {
          if (that.isStart) {
            that.isStart = false
            for (let i = 0; i < that.buttonVoList.length; i++) {
              let button = that.buttonVoList[i]
              if (button.type == 'submit' && button.attribute.skipFirst == 'true') {
                that.submit(button)
                break
              }
            }
          }
        }
      },
      /*刷新父组件*/
      refreshParent: function() {
        this.father.refreshParent()
      },
      /*流程选人框的回调，执行按钮实际动作*/
      selectUserBack(data) {
        const that = this
        that.spinning++
        putAction(this.currentUrl, data).then((res) => {
          if (res.success) {
            that.messageUtil.success(res.message)
            that.refresh()
            that.refreshParent()
          } else {
            that.messageUtil.warning(res.message)
          }
        }).finally(() => {
          that.spinning--
        })
      },
      /*跳转、退回指定节点等动作选择目标节点后的回调*/
      doActivityBack(activity) {
        this.button.attribute.targetActivityId = activity.id
        if (this.activityType == 'jump') {
          this.currentUrl = this.url.jump + '?taskId=' + this.button.attribute.taskId + '&targetActivityId=' + this.button.attribute.targetActivityId
          this.$refs.bpmSelectUserDialog.open(this.button, activity)
        } else if (this.activityType == 'rejectWantTask') {
          this.currentUrl = this.url.rejectWantTask + '?taskId=' + this.button.attribute.taskId + '&targetActivityId=' + this.button.attribute.targetActivityId
          this.$refs.bpmSelectUserDialog.openNoUser(this.button, undefined, activity)
        }
      },
      /*打开切换任务选择对话框*/
      changeCurrentTask() {
        this.taskInstanceVoList.forEach(vo => {
          let text = ''
          if (!vo.passRound) {
            text += vo.taskName + '-'
          }
          text += vo.identityString
          vo.text = text
        })
        this.$refs.changeTaskDialog.visible = true
      },
      /*切换任务*/
      changeTask(task) {
        if (task.id == this.bpmId) {
          return
        }
        /*若新任务和当前任务地址一致，则只需要刷新操作按钮等，否则整个页面需要重新渲染*/
        if (task.pcUrl != this.currentTaskInstanceVo.pcUrl) {
          this.father.changeTask(task)
        } else {
          this.bpmId = task.id
          this.bpmIdType = 'taskId'
          this.refresh()
        }
      },
      handleResize(event) {
        this.fullWidth = document.documentElement.clientWidth
      }
    },
    mounted() {
      this.bpmId = this.father.bpmId
      this.bpmIdType = this.father.bpmIdType
      this.getBpmOperateVoUrl = this.father.getBpmOperateVoUrl
      // this.refresh();
      this.setButtonDatas(this.father.buttonDatas)
      this.targetOffset = document.body.clientHeight / 2
    },
    watch: {
      /*通过监听id变化，刷新按钮权限*/
      /*id: {
        handler(newName, oldName) {
          this.bpmId = this.idType == "formCode" ? this.father.formCode : this.id;
          this.bpmIdType = this.idType;
          this.refresh();
        },
        immediate: true
      }*/
    },
    computed: {
      processInstanceStatus() {
        let result = ''
        if (this.currentTaskInstanceVo != null) {
          if (this.currentTaskInstanceVo.reader) {
            result = this.$t('m.bpm.entity.readerName')
          } else {
            if (!this.currentTaskInstanceVo.passRound) {
              result += (this.currentTaskInstanceVo.taskName ? (this.currentTaskInstanceVo.taskName + '-') : '')
            }
            result += this.currentTaskInstanceVo.identityString
          }
        }
        return result
      },
      identity() {
        let result = ''
        if (this.currentTaskInstanceVo != null) {
          if (this.currentTaskInstanceVo.reader) {
            result = this.$t('m.bpm.entity.readerName')
          } else {
            if (!this.currentTaskInstanceVo.passRound) {
              result += (this.currentTaskInstanceVo.taskName ? (this.currentTaskInstanceVo.taskName + '-') : '')
            }
            result += this.currentTaskInstanceVo.identityString
            if (this.currentTaskInstanceVo.delegateTask) {
              result += '('+this.$t('m.bpm.verify.tip_current_task_delegated')+'：' + this.currentTaskInstanceVo.assigneeName
              if (this.currentTaskInstanceVo.assigneeDeptName) {
                result += '/' + this.currentTaskInstanceVo.assigneeDeptName
              }
              result += ')'
            }
            if (this.currentTaskInstanceVo.ownerName) {
              result += '('+this.$t('m.bpm.verify.tip_assignor')+'：' + this.currentTaskInstanceVo.ownerName
              if (this.currentTaskInstanceVo.ownerDeptName) {
                result += '/' + this.currentTaskInstanceVo.ownerDeptName
              }
              result += ')'
            }

          }

          if (this.currentTaskInstanceVo.suspend) {
            result += '（'+this.$t('m.bpm.verify.tip_process_suspended')+'）'
          }
        }
        return result
      },
      getAffixTarget() {
        // 取消流程按钮区域的固钉样式，因为tab页签的样式问题
        // const modalBody = document.getElementsByClassName('ant-modal-body')
        // const main = document.getElementsByClassName('main')
        // if (modalBody && modalBody.length > 0) {
        //   return () => modalBody[0]
        // } else if (main && main.length > 0) {
        //   return () => main[0]
        // } else {
        //   return () => window
        // }
        return null
      },
      size() {
        let n = (this.maxWidth - 44) / 150
        n = Math.floor(n)
        return n > 1 ? n : 1
      },
      maxWidth() {
        let leftWidth = 540// 350 + 120 + 24 + 24 + 20
        return this.fullWidth > leftWidth ? this.fullWidth - leftWidth : 0
      }
    },
    created() {
      //console.log("-------------------------", this.hiddenButton)
      window.addEventListener('resize', this.handleResize)
    },
    beforeDestroy() {
      window.removeEventListener('resize', this.handleResize)
    }
  }
</script>
<style lang="less">
  .bpm-button {
    .bpm-title-toolbar {
      height: 56px;
      line-height: 56px;
      padding: 0px 10px 0px 10px;
      background: #fff;
      border-bottom: 1px solid #e8e8e8;

      .bpm-title-group {
        height: 56px;
        line-height: 56px;
        font-size: 18px;
        font-weight: 600;
        margin: 0px 0px 0px 10px;
        display: inline-block;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;

        em {
          display: inline-block;
          font-size: 12px;
          height: 20px;
          line-height: 20px;
          border: 1px solid #FF9900;
          color: #FF9900;
          padding: 0 6px;
          border-radius: 20px;
          font-style: normal;
        }
      }

      .bpm-button-group {
        display: inline-block;
        float: right;

        .ant-btn {
          margin: 6px 6px;
        }
      }
    }
  }
</style>
